Skip to content

fix(ci): skip AI review when a PR exceeds GitHub's diff-file limit - #2536

Merged
happyhuman merged 1 commit into
mainfrom
ci/skip-ai-review-when-diff-too-large
Aug 17, 2026
Merged

happyhuman merged 1 commit into
mainfrom
ci/skip-ai-review-when-diff-too-large

Conversation

@happyhuman

Copy link
Copy Markdown
Collaborator

gh pr diff reads GET /repos/{owner}/{repo}/pulls/{n} with the diff media type, and that endpoint refuses above 300 files:

HTTP 406: Sorry, the diff exceeded the maximum number of files (300).
PullRequest.diff too_large

PR #2535 changes 804 files, so all three reviews died in "Fetch the PR diff for the reviewer". 406 is deterministic, so the step's three retries could never recover it, and its exhausted-loop path is fatal by design — the right instinct, since a review that silently saw no diff is worse than no review, but it cannot tell "transient" from "will never fit through this endpoint".

Catch it one step earlier instead. The guard already paginates /pulls/{n}/files, which has no such cap, so the file count is in hand before anything asks for the diff. Over the limit, the review is skipped with a comment saying why, rather than failing three checks red.

Folded into the existing guard rather than added alongside it: seven later steps hang off its skip output, and reusing the id leaves all of them untouched. That means the step-level event gate moves inline, which is also more correct — the file limit is a hard API fact and applies on every event, while the new-file-only rule is policy and stays on the automatic trigger, so a maintainer can still force a review by hand.

Two counts now come from one pagination pass. The non-added count uses awk rather than grep -cv ... || true: grep exits 1 on no match, which set -e reads as failure and an all-added PR triggers, but || true also swallows grep's exit >1 on a real error, leaving the count empty — and [[ "" -eq 0 ]] is true in bash, so the guard would skip a PR it never managed to read and report it as "only adds new files". awk exits 0 with no matches and non-zero only on a real error, which pipefail turns into the loud failure it should be.

Verified by extracting the step's run: block and executing it against live PRs with gh pr comment stubbed (#2535 skips on both pull_request and issue_comment; #2507 skips only on pull_request; #2531 is unaffected), and against a synthetic API for the boundary and error paths (300 files pass, 301 skip, a failing gh api or an unreadable file aborts instead of silently skipping).

`gh pr diff` reads GET /repos/{owner}/{repo}/pulls/{n} with the diff media
type, and that endpoint refuses above 300 files:

    HTTP 406: Sorry, the diff exceeded the maximum number of files (300).
    PullRequest.diff too_large

PR #2535 changes 804 files, so all three reviews died in "Fetch the PR diff
for the reviewer". 406 is deterministic, so the step's three retries could
never recover it, and its exhausted-loop path is fatal by design — the right
instinct, since a review that silently saw no diff is worse than no review,
but it cannot tell "transient" from "will never fit through this endpoint".

Catch it one step earlier instead. The guard already paginates
/pulls/{n}/files, which has no such cap, so the file count is in hand before
anything asks for the diff. Over the limit, the review is skipped with a
comment saying why, rather than failing three checks red.

Folded into the existing guard rather than added alongside it: seven later
steps hang off its `skip` output, and reusing the id leaves all of them
untouched. That means the step-level event gate moves inline, which is also
more correct — the file limit is a hard API fact and applies on every event,
while the new-file-only rule is policy and stays on the automatic trigger,
so a maintainer can still force a review by hand.

Two counts now come from one pagination pass. The non-added count uses awk
rather than `grep -cv ... || true`: grep exits 1 on no match, which `set -e`
reads as failure and an all-added PR triggers, but `|| true` also swallows
grep's exit >1 on a real error, leaving the count empty — and `[[ "" -eq 0 ]]`
is true in bash, so the guard would skip a PR it never managed to read and
report it as "only adds new files". awk exits 0 with no matches and non-zero
only on a real error, which pipefail turns into the loud failure it should be.

Verified by extracting the step's run: block and executing it against live
PRs with `gh pr comment` stubbed (#2535 skips on both pull_request and
issue_comment; #2507 skips only on pull_request; #2531 is unaffected), and
against a synthetic API for the boundary and error paths (300 files pass,
301 skip, a failing `gh api` or an unreadable file aborts instead of
silently skipping).
@happyhuman happyhuman self-assigned this Aug 17, 2026
@happyhuman
happyhuman merged commit 3a5de64 into main Aug 17, 2026
8 checks passed
@happyhuman
happyhuman deleted the ci/skip-ai-review-when-diff-too-large branch August 17, 2026 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant